#include <iostream>
#include <vector>
#include <stack>

using namespace std;

struct ListNode
{
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(nullptr) { }
};

class Solution {
public:
    vector<int> reversePrint(ListNode* head)
    {
        vector<int> result;
        if (!head) {  // 输入为空
            return result;
        }
        while (head->next != nullptr) {
            result.insert(result.begin(), head->val);
            head = head->next;
        }
        result.insert(result.begin(), head->val);  // 处理最后一个元素
        return result;
    }

    vector<int> reversePrint_2(ListNode *head)
    {
        // 递归
        recur(head);
        return res;
    }

    vector<int> reversePrint_3(ListNode *head)
    {
        stack<int> stk;
        while (head != nullptr) {
            stk.push(head->val);
            head = head->next;
        }
        vector<int> res;
        while (!stk.empty()) {
            res.push_back(stk.top());
            stk.pop();
        }
        return res;
    }
private:
    vector<int> res;
    void recur(ListNode *head)
    {
        if (head == nullptr) {
            return;
        }
        recur(head->next);
        res.push_back(head->val);
    }
};

int main()
{
    cout << "Hello World!" << endl;
    return 0;
}
